package net.tarine.gastronomi.client.forms;

import net.tarine.gastronomi.client.AuthSingleton;
import net.tarine.gastronomi.client.ClientConst;
import net.tarine.gastronomi.client.IAuthenticatedWidget;
import net.tarine.gastronomi.shared.to.ForumMessageTo;
import net.tarine.gastronomi.shared.to.GasUserTo;

import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.InlineHTML;

public class MessageDisplayPanel extends FlowPanel implements IAuthenticatedWidget {

	//private GasUserTo user = null;
	private ForumMessageTo forumMessageTo;
	
	public MessageDisplayPanel(ForumMessageTo forumMessageTo) {
		this.forumMessageTo = forumMessageTo;
		AuthSingleton.get().authorizeWidget(this);
	}
	@Override
	public void unlockWidget(GasUserTo user) {
		//this.user=user;
		draw();
	}
	
	private void draw() {
		HorizontalPanel msgHeader = new HorizontalPanel();
		msgHeader.add(new Image("img/user.jpg"));
		msgHeader.setStyleName("message-user-panel");
		//paintUser
		GasUserTo gasUserTo = forumMessageTo.getGasUserTo();
		FlowPanel userPanel = new FlowPanel();
		userPanel.add(new InlineHTML("<b>"+gasUserTo.getNickname()+"</b> "));
		userPanel.add(new InlineHTML("("+gasUserTo.getEmail()+") "));
		if (gasUserTo.getPhoneNumber() != null) userPanel.add(new InlineHTML("tel. "+gasUserTo.getPhoneNumber()));
		userPanel.add(new HTML("Inviato il "+ClientConst.FORMAT_DATETIME.format(forumMessageTo.getCreationDt())));
		userPanel.setStyleName("message-details-panel");
		msgHeader.add(userPanel);
		this.add(msgHeader);
		//paintMessage
		FlowPanel messagePanel = new FlowPanel();
		messagePanel.setStyleName("message-panel");
		messagePanel.add(new HTML(forumMessageTo.getText()));
		this.add(messagePanel);
	}
}
